#include "rewine/LoaderSingleton.hpp"
#include "rewine/LoggerSingleton.hpp"

#include "infra/Shelter.hpp"

using std::shared_ptr;
using std::unique_ptr;

namespace rewine
{

unique_ptr<Loader> g_Loader;

int g_argc;
char **g_argv;
char **g_envp;

void __attribute__((constructor(102)))
loader_init(int argc, char *argv[], char *envp[]) {
    g_argc = argc;
    g_argv = argv;
    g_envp = envp;

    Shelter shelter;
    shelter.add([](void) -> void {
        exit(EXIT_FAILURE);
    });

    g_Loader = std::make_unique<Loader>();
    if (!g_Loader) {
        g_Logger->fatal(__FLF__, "Loader construction failed");
        return;
    }
    //g_Loader->getPathResolver().add(".");
    shelter.toggle(false);
}

} // namespace rewine
